/* eslint-disable prefer-arrow-callback */
/* eslint-disable jsdoc/no-restricted-syntax */
/**
 * @template {PromiseLike<any>}T
 * @param {string[]} resultQueue
 * @param {{resolve<T>(value?: PromiseLike<T>): T, }} promiseA
 * @returns {*}
 */
export function promiseNested3(resultQueue, promiseA) {
  return promiseA
    .resolve()
    .then(
      function then1() {
        resultQueue.push("1");
        promiseA.resolve().then(function then11() {
          resultQueue.push("2");
          promiseA.resolve().then(function then111() {
            resultQueue.push("3");
            promiseA.resolve().then(function then1111() {
              resultQueue.push("4");
            });
            resultQueue.push("5");
          });
          resultQueue.push("6");
        });
        resultQueue.push("7");
      },
      function catch1() {
        resultQueue.push("8");
      },
    )
    .finally(function fin1() {
      resultQueue.push("9");
    });
}

/**
 * @template {PromiseLike<any>}T
 * @param {string[]} resultQueue
 * @param {{resolve<T>(value?: PromiseLike<T>): T, }} promiseA
 * @returns {Promise<T>}
 */
export async function promiseNested3Await(resultQueue, promiseA) {
  return await promiseA
    .resolve()
    .then(
      async function then1() {
        resultQueue.push("1");
        await promiseA.resolve().then(async function then11() {
          resultQueue.push("2");
          await promiseA.resolve().then(async function then111() {
            resultQueue.push("3");
            await promiseA.resolve().then(function then1111() {
              resultQueue.push("4");
            });
            resultQueue.push("5");
          });
          resultQueue.push("6");
        });
        resultQueue.push("7");
      },
      function catch1() {
        resultQueue.push("8");
      },
    )
    .finally(function fin1() {
      resultQueue.push("9");
    });
}
